﻿
let State = {
    state:-1,
};
let Nums = [
    {
    num:'全部'
    },
    {
    num: '已完成'
},
{
    num: '已取消'
},
{
    num: '进行中'
},
{
    num: '待支付'
}
];
Peng_Select.CreateElement('OState', Nums, 'num', (res) => {
    if (res.num == '已完成') {
        State.state = 0;
    } if (res.num == '已取消') {
        State.state = 1;
    }  if (res.num == '进行中') {
        State.state = 2;
    } if (res.num == '待支付') {
        State.state = 3;
    } if (res.num == '全部') {
        State.state = -1;
    }
    GetOrder("", State.state);
    Peng.closeload(loadTable);
});
var loadTable
function BindOrder(obj) {
    layui.use("table", function () {
        var table = layui.table;
        table.render({
            elem: "#test",
            data: obj,
            align: 'center',
            cellMinWidth: 80,
              parseData: function (res) { //res 即为原始返回的数据
                  return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            },
            cols: [[
                { field: 'Number', title: '订单号', align: 'center' },
                { field: 'Type', title: '订单类型', align: 'center', templet:'#type' },
                { field: 'money', title: '订单金额', align: 'center' },
                { field: 'count', title: '商品数量', align: 'center' },
                { field: 'PayType', title: '支付类型', align: 'center', templet:"#PayType" },
                { field: 'createTime', title: '创建时间', align: 'center' },
                { field: 'isPay', title: '是否支付', align: 'center', templet:'#IsPay' },
                { field: 'state', title: '订单状态', align: 'center', templet:'#state' },
                { field: 'UserName', title: '用户', align: 'center' },
                { field: 'phone', title: '电话号码', align: 'center' },
                { field: 'TableName', title: '桌子', align: 'center' },
                { field: 'occupy', title: '就餐人数', align: 'center' },
                { title: '操作', align: 'center', toolbar: '#detail', width: 400 }

               
            ]],
            limit: 10,
            limits: [10, 20, 50, 100],
            page: true,
            id:'id'
        });
      
        table.on('tool(table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            switch (layEvent) {
                case "deltails":
                    sessionStorage.setItem("id", data.id);
                    location.href = "/Order/OrderDetails";
                    break;
                case "edit":
                    sessionStorage.setItem("oid", data.id);
                    location.href = "/Order/OrderPay";
                    break;
                case "PayRecords":
                    sessionStorage.setItem("oid",data.id);
                    location.href = "/Order/PayHtml";
            }
        });
    })
    Peng.closeload(loadTable);
}
window.onload = function () {
    GetOrder();
}

function GetOrder(key, state) {
    loadTable = Peng.load({ box: 'Cols', style: 'circle', color: 'ZhutiSe', content: '加载订单数据中.....' });
    $.get("/Order/GetALLOrder", {
        key: key,
        state: state
    }).then((res) => {
          BindOrder(res.data.data);
        
    });
}
var query = function () {

    GetOrder($("#MyOrder").val(), State.state);
}
